<%#
 Copyright 2013-2018 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
os:
  - linux
services:
  - docker
language: node_js
node_js:
  - "<%= NODE_VERSION %>"
jdk:
  - oraclejdk8
sudo: false
cache:
  directories:
    - node
    - node_modules
<%_ if (buildTool === 'maven') { _%>
    - $HOME/.m2
<%_ } else if (buildTool === 'gradle') { _%>
    - $HOME/.gradle
<%_ } _%>
<%_ if (clientPackageManager === 'yarn') { _%>
    - $HOME/.yarn-cache
<%_ } _%>
env:
  global:
    - NODE_VERSION=<%= NODE_VERSION %>
    - SPRING_OUTPUT_ANSI_ENABLED=ALWAYS
    - SPRING_JPA_SHOW_SQL=false
before_install:
  - jdk_switcher use oraclejdk8
  - java -version
  - sudo /etc/init.d/mysql stop
  - sudo /etc/init.d/postgresql stop
  <%_ if (clientPackageManager === 'npm') { _%>
  - nvm install $NODE_VERSION
  - npm install -g npm
  - node -v
  - npm -v
  <%_ } _%>
  <%_ if (clientPackageManager === 'yarn') { _%>
  # Repo for Yarn
  - curl -o- -L https://yarnpkg.com/install.sh | bash
  - export PATH=$HOME/.yarn/bin:$PATH
  <%_ } _%>
install:
  <%_ if (clientPackageManager === 'npm') { _%>
  - npm install
  <%_ } _%>
  <%_ if (clientPackageManager === 'yarn') { _%>
  - yarn install
  <%_ } _%>
script:
<%_ if (buildTool === 'maven') { _%>
  - chmod +x mvnw
  - ./mvnw clean test
<%_ } else if (buildTool === 'gradle') { _%>
  - chmod +x gradlew
  - ./gradlew clean test
<%_ } _%>
<%_ if (applicationType !== 'microservice') { _%>
    <%_ if (clientPackageManager === 'yarn') { _%>
  - yarn test<%= frontTests%>
    <%_ } else if (clientPackageManager === 'npm') { _%>
  - npm test<%= frontTests%>
    <%_ } _%>
<%_ } _%>
<%_ if (buildTool === 'maven') { _%>
  <%_ if (cicdIntegrations.includes('sonar')) { _%>
  - ./mvnw org.jacoco:jacoco-maven-plugin:prepare-agent sonar:sonar <% if (sonarOrga) { %>-Dsonar.organization=<%= sonarOrga %> <% } %>-Dsonar.host.url=<%= sonarUrl %> -Dsonar.login=$SONAR_TOKEN
  <%_ } _%>
  - ./mvnw verify -Pprod -DskipTests
  <%_ if (cicdIntegrations.includes('heroku')) { _%>
  - ./mvnw com.heroku.sdk:heroku-maven-plugin:2.0.5:deploy -DskipTests -Pprod -Dheroku.buildpacks=heroku/jvm -Dheroku.appName=<%= herokuAppName %>
  <%_ } _%>
<%_ } else if (buildTool === 'gradle') { _%>
  <%_ if (cicdIntegrations.includes('sonar')) { _%>
  - ./gradlew sonarqube --no-daemon <% if (sonarOrga) { %>-Dsonar.organization=<%= sonarOrga %> <% } %>-Dsonar.host.url=<%= sonarUrl %> -Dsonar.login=$SONAR_TOKEN
  <%_ } _%>
  - ./gradlew bootWar -Pprod -x test
  <%_ if (cicdIntegrations.includes('heroku')) { _%>
  - ./gradlew deployHeroku
  <%_ } _%>
<%_ } _%>
notifications:
  webhooks:
    on_success: change  # options: [always|never|change] default: always
    on_failure: always  # options: [always|never|change] default: always
    on_start: false     # default: false
